from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
import os
from common.libs.UrlManager import UrlManager


class Application(Flask):
    def __init__(self, import_name, template_folder=None, root_path=None,static_folder=None):
        super(Application, self).__init__(import_name, template_folder=template_folder, root_path=root_path,
                                          static_folder=static_folder)
        self.config.from_pyfile('config/base_setting.py')   # 从文件获取配置

        if 'op_config' in os.environ:
            self.config.from_pyfile('config/%s_setting.py' % os.environ['op_config'])  # 从环境变量判断配置文件

        db.init_app(self)   # 初始化db


db = SQLAlchemy()
app = Application(__name__, template_folder=os.getcwd()+"/web/templates/", root_path=os.getcwd(),static_folder='static')
manager = Manager(app)

'''
函数模板注入
'''
# app.add_template_global(UrlManager.buildStaticUrl, 'buildStaticUrl')
# app.add_template_global(UrlManager.buildUrl, 'buildUrl')
# app.add_template_global(UrlManager.buildImageUrl, 'buildImageUrl')



